package com.ruoyi.project.monitor.redismonitor.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.monitor.redismonitor.domain.RedisMonitor;
import com.ruoyi.project.monitor.redismonitor.service.IRedisMonitorService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * Redis监控Controller
 * 
 * @author shixiangwen
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/monitor/redismonitor")
public class RedisMonitorController extends BaseController
{
    private String prefix = "monitor/redismonitor";

    @Autowired
    private IRedisMonitorService redisMonitorService;

    @RequiresPermissions("monitor:redismonitor:view")
    @GetMapping()
    public String redismonitor()
    {
        return prefix + "/redismonitor";
    }

    /**
     * 查询Redis监控列表
     */
    @RequiresPermissions("monitor:redismonitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RedisMonitor redisMonitor)
    {
        startPage();
        List<RedisMonitor> list = redisMonitorService.selectRedisMonitorList(redisMonitor);
        return getDataTable(list);
    }

    /**
     * 导出Redis监控列表
     */
    @RequiresPermissions("monitor:redismonitor:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RedisMonitor redisMonitor)
    {
        List<RedisMonitor> list = redisMonitorService.selectRedisMonitorList(redisMonitor);
        ExcelUtil<RedisMonitor> util = new ExcelUtil<RedisMonitor>(RedisMonitor.class);
        return util.exportExcel(list, "redismonitor");
    }

    /**
     * 新增Redis监控
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存Redis监控
     */
    @RequiresPermissions("monitor:redismonitor:add")
    @Log(title = "Redis监控", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RedisMonitor redisMonitor)
    {
        return toAjax(redisMonitorService.insertRedisMonitor(redisMonitor));
    }

    /**
     * 修改Redis监控
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RedisMonitor redisMonitor = redisMonitorService.selectRedisMonitorById(id);
        mmap.put("redisMonitor", redisMonitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存Redis监控
     */
    @RequiresPermissions("monitor:redismonitor:edit")
    @Log(title = "Redis监控", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RedisMonitor redisMonitor)
    {
        return toAjax(redisMonitorService.updateRedisMonitor(redisMonitor));
    }

    /**
     * 删除Redis监控
     */
    @RequiresPermissions("monitor:redismonitor:remove")
    @Log(title = "Redis监控", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(redisMonitorService.deleteRedisMonitorByIds(ids));
    }
}
